﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TextEditorDP
{
    public class Iterator<Item> : IAbstractIterator<Item>
    {
        private CList<Item> _collection;
        private int _current = 0;
        private int _step = 1;

        // Constructor
        public Iterator(CList<Item> collection)
        {
            this._collection = collection;
        }

        // Gets first item
        public Item First()
        {
            _current = 0;
            return _collection.Get(_current);
        }

        // Gets next item
        public Item Next()
        {
            _current += _step;
            if (!IsDone)
                return _collection.Get(_current);
            else
                return default(Item);
        }

        // Gets or sets stepsize
        public int Step
        {
            get { return _step; }
            set { _step = value; }
        }

        // Gets current iterator item
        public Item CurrentItem
        {
            get { return _collection.Get(_current); }
        }

        // Gets whether iteration is complete
        public bool IsDone
        {
            get { return _current >= _collection.Count; }
        }
    }
}
